$(function () {
  const layer = layui.layer
  const form = layui.form
  // 添加表单自定义校验规则
  form.verify({

    //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
    pwd: [
      /^[\S]{6,12}$/
      , '密码必须6到12位，且不能出现空格'
    ],
  })


  document.querySelector('form').addEventListener('submit', (e) => {
    e.preventDefault()
    const username = document.querySelector('#username').value.trim()
    const password = document.querySelector('#password').value.trim()
    if (username.length <= 0 || password.length <= 0) {
      return alert('输入内容不可为空')
    }
    const url = 'http://124.223.14.236:3001/api/user/login'
    const dataObj = { username, password }

    axios.post(url, dataObj).then(({ data }) => {
      console.log(data);
      if (!data.success) {
        return layer.msg(data.msg)
      }
      layer.msg('登录成功!')
      location.href = ''
    })

  })
})